from odoo import http, fields
from odoo.http import request
from ...data_models.api_models import RPInterfaceModelForGet as RP_Get
from ...tools.decorator import validate_rp_api, exception_handler
from ..abstract_interface.ship_order import APIShipOrder
from ...tools.encapsulation import valid_response, invalid_business, invalid_response
from ...static import request_schema_json


class APIShipOrderImplement(APIShipOrder):
    """
    管理订单类接口
    """

    @exception_handler
    @validate_rp_api(schema=request_schema_json.get_order_list,token=True)
    @http.route(route='/api/order/get_order_list', auth='none', methods=['GET'], cors="*", csrf=False)
    def get_order_list(self, **kwargs):
        """ 获取订单列表 """
        _customer_id = request.customerid
        pay_status = kwargs.get('pay_status')
        if pay_status == 'paid':
            pay_flag = [True]
        elif pay_status == 'unpaid':
            pay_flag = [False]
        else:
            pay_flag = [True, False]
        rp_get = RP_Get(kwargs.get('page',1), kwargs.get('limit',10))

        rp_ship_order_ids = request.env['rp.ship.order'].sudo().search([('customer_id', '=', _user_id), ('pay_flag', 'in', pay_flag)],
                                                                       order='create_date DESC', offset=rp_get.offset, limit=rp_get.limit)
        print(rp_ship_order_ids)
        data = {'order_list': rp_ship_order_ids}
        return valid_response(data)

    @http.route(route='/api/order/get_order', auth='none', methods=['GET'], cors="*", csrf=False)
    def get_order(self, **kw):
        """ 获取订单（一个或多个） """
        pass
